package cn.tk.dbtest;

import java.sql.ResultSet;
import java.util.Date;

public class TestMain {
	private int id=0;
	private String name="";
	private Date date=new Date();
	
	public void testQuery(){
		
		DBTest db=new DBTest();
		db.connect("", "", "mytest", "root", "1234");
		ResultSet rs=db.query("select * from test");

		try {
			while(rs.next()){
				
				
				id=rs.getInt("id");
				name=rs.getString("name");
				date=rs.getDate("date");
				System.out.println("id:" + id + " name:" + name + " date:" + date);
			}
		} catch (Exception e) {

			e.printStackTrace();
		}finally{
			db.close();
			db=null;
		}
	}
	
	
	public void testInsert(){
		
		DBTest db=new DBTest();
		db.connect("", "", "mytest", "root", "1234");
		int count=db.update("insert into mytest.test(name,date) values(\'aaa\',\'2013-12-1\')");
		System.out.println("insert count:"+count);
		db.close();
		db=null;

	}

	public static void main(String[] args) {
		TestMain test=new TestMain();
		test.testInsert();
		test.testQuery();

	}

}
